#region

using System.Collections.Generic;
using System.Text.RegularExpressions;

#endregion

namespace MediaController.Extractor
{
    public class CommandLine
    {
        
        private readonly List<string> Arguments = new List<string>();
        private readonly Dictionary<string, Option> Options = new Dictionary<string, Option>();

        
        public CommandLine(string[] Args)
        {
            var regex = new Regex("^-{1,2}|^/", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            new Regex("^['\"]?(.*?)['\"]?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            foreach (var str in Args)
            {
                if (!regex.IsMatch(str))
                {
                    Arguments.Add(str);
                }
            }
        }

        // Properties
        public Option this[string Param]
        {
            get { return Options[Param]; }
        }

        public string this[int Index]
        {
            get
            {
                if (Index >= Arguments.Count)
                {
                    return null;
                }
                return Arguments[Index];
            }
        }

        internal void AddOption(Option option)
        {
            Options.Add(option.Name, option);
        }

        // Nested Types

        #region Nested type: Option

        public class Option
        {
            
            private readonly bool _hasValue;
            private readonly string _name;
            private string _value;

            
            public Option(string name, bool hasValue)
            {
                _name = name;
                _hasValue = hasValue;
            }

            // Properties
            public bool HasValue
            {
                get { return _hasValue; }
            }

            public string Name
            {
                get { return _name; }
            }

            public string Value
            {
                get { return _value; }
                set { _value = value; }
            }
        }

        #endregion
    }
}